package com.atguigu;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class excel {
    public static void main(String[] args) {
        List<student> list = new ArrayList<>();

        list.add(new student(1,"大哥",18,true));
        list.add(new student(1,"二弟",18,true));
        list.add(new student(1,"三第",18,true));
        list.add(new student(1,"小老弟",18,true));

        EasyExcel.write("C:\\Users\\ASUS\\Desktop\\hello.xls",student.class)
                .sheet("学生列表一")
                .doWrite(list);
    }

    /*
    * 往多个列表中注入数据
    *   手动关闭流
    * */
    @Test
    public void test01(){
//        定义路径
        String Url="C:\\Users\\ASUS\\Desktop\\abc.xls";

        List<student> list1 = new ArrayList<>();
        list1.add(new student(1,"大哥",18,true));
        list1.add(new student(1,"二弟",18,true));

        List<student> list2 = new ArrayList<>();
        list2.add(new student(3,"三第",18,true));
        list2.add(new student(4,"小老弟",18,true));

//        定义excel表的位置以及姓名信息
        ExcelWriter execlWriter = EasyExcel.write(Url,student.class).build();

//        定义sheet表单信息
        WriteSheet studentList1 = EasyExcel.writerSheet(0, "学生列表1").build();
        WriteSheet studentList2 = EasyExcel.writerSheet(1, "学生列表2").build();

        execlWriter.write(list1,studentList1);
        execlWriter.write(list2,studentList2);

//        关闭流量
        execlWriter.finish();
    }
}
